<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生信息" prop="stuName">
        <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名或学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="学生学号" prop="sno">
        <el-input v-model="queryParams.sno" placeholder="请输入学生学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="请假类型" prop="leaveType">
        <el-select v-model="queryParams.leaveType" style="width:100%;" placeholder="请选择请假类型" clearable>
          <el-option v-for="dict in dict.type.leave_types" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['backend:eliminate:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="eliminateList">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="学生姓名" align="center" prop="stuName" />
      <el-table-column label="学号" align="center" prop="sno" />
      <el-table-column label="请假类型" align="center" prop="leaveType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.leave_types" :value="scope.row.leaveType" />
        </template>
      </el-table-column>
      <el-table-column label="请假天数" align="center" prop="duration">
        <template slot-scope="scope">
          {{ scope.row.duration / 10 }}天
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" prop="beginTime" />
      <el-table-column label="结束时间" align="center" prop="endTime" />
      <el-table-column label="销假时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleInfo(scope.row)"
            v-hasPermi="['backend:eliminate:query']">详细信息</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['backend:eliminate:edit']">修改</el-button> -->
          <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['backend:eliminate:remove']">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 查看销假记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form class="eliminate-form" ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row class="eliminate-row">
          <el-col class="eliminate-col-title" :span="8">学生姓名</el-col>
          <el-col class="eliminate-col-title" :span="8">学号</el-col>
          <el-col class="eliminate-col-title" :span="4">请假类型</el-col>
          <el-col class="eliminate-col-title" :span="4">假期类别</el-col>
        </el-row>
        <el-row class="eliminate-row">
          <el-col class="eliminate-col-content" label="学生姓名" :span="8">{{ form.stuName }}</el-col>
          <el-col class="eliminate-col-content" label="学号" :span="8">{{ form.sno }}</el-col>
          <el-col class="eliminate-col-content" label="请假类型" :span="4">
            <dict-tag :options="dict.type.leave_types" :value="form.leaveType" />
          </el-col>
          <el-col class="eliminate-col-content" label="假期类别" :span="4">
            <el-tag v-if="form.parentLevelId != null" type="warning">延假</el-tag>
            <el-tag v-else>请假</el-tag>
          </el-col>
        </el-row>


        <el-row class="eliminate-row">
          <el-col class="eliminate-col-title" :span="4">开始时间</el-col>
          <el-col class="eliminate-col-title" :span="4">结束时间</el-col>
          <el-col class="eliminate-col-title" :span="8">销假时间</el-col>
          <el-col class="eliminate-col-title" :span="4">累计天数</el-col>
          <el-col class="eliminate-col-title" :span="4">假期状态</el-col>
        </el-row>
        <el-row class="eliminate-row">
          <el-col class="eliminate-col-content" label="开始时间" :span="4">{{ form.beginTime }}</el-col>
          <el-col class="eliminate-col-content" label="结束时间" :span="4">{{ form.endTime }}</el-col>
          <el-col class="eliminate-col-content" label="销假时间" :span="8">{{ form.createTime }}</el-col>
          <el-col class="eliminate-col-content" label="累计天数" :span="4">{{ form.duration / 10 }}天</el-col>
          <el-col class="eliminate-col-content" label="假期状态" :span="4">
            <dict-tag :options="dict.type.vacation_status" :value="form.vacationStatus"
              v-if="form.vacationStatus != null" />
            <el-tag v-else>审核中</el-tag>
          </el-col>
        </el-row>


        <el-row class="eliminate-row">
          <el-col class="eliminate-col-title" :span="24">申请原因</el-col>
        </el-row>
        <el-row class="eliminate-row">
          <el-col class="eliminate-col-content" label="申请原因" :span="24">{{ form.cause }}</el-col>
        </el-row>

        <el-row class="eliminate-row">
          <el-col class="eliminate-col-title" :span="12">销假照片</el-col>
          <el-col class="eliminate-col-title" :span="12">销假地点</el-col>
        </el-row>
        <el-row class="eliminate-row">
          <el-col class="eliminate-col-content" label="销假照片" :span="12" style="height: 30vh;">
            <el-image :src="form.path" :preview-src-list="srcList" style="width: 23%; height: 29.9vh;" fit="cover"
              disabled />
          </el-col>
          <el-col class="eliminate-col-content" label="销假地点" :span="12" style="height: 30vh;">
            <div style="width: 100%; height:29.9vh">
              <el-amap ref="elAmap" vid="amapDemo" :zoom="zoom" :center="form.location" :amap-manager="amapManager">
                <el-amap-marker :topWhenClick="true" title="销假位置" />
              </el-amap>
            </div>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEliminate, getEliminate, delEliminate, addEliminate, updateEliminate } from "@/api/backend/eliminate";
// 地图组件
import VueAMap from 'vue-amap';

let amapManager = new VueAMap.AMapManager();
export default {
  name: "Eliminate",
  dicts: ['leave_types', 'vacation_status'],
  data() {
    return {
      marker: {
        iconPath: "@/assets/images/location.png",
      },
      amapManager: amapManager,
      zoom: 13,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 图片列表
      srcList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销假记录表格数据
      eliminateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuName: null,
        leaveType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询销假记录列表 */
    getList() {
      this.loading = true;
      listEliminate(this.queryParams).then(response => {
        this.eliminateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        applyLeaveId: null,
        location: [0, 0],
        fileId: null,
        disclaimerId: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 详细信息按钮操作 */
    handleInfo(row) {
      this.reset();
      const id = row.id || this.ids
      getEliminate(id).then(response => {
        this.form = response.data;
        this.form.path = process.env.VUE_APP_BASE_API + this.form.path;
        this.form.leaveType = JSON.stringify(this.form.leaveType)
        this.form.location = this.form.location.split(" ");
        this.open = true;
        this.title = "销假详细信息";
        this.srcList[0] = this.form.path;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('backend/eliminate/export', {
        ...this.queryParams
      }, `eliminate_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.eliminate-col-title {
  background-color: #FAFAFA;
}

.eliminate-col-title,
.eliminate-col-content {
  display: inline-block;
  height: 45px;
  line-height: 45px;
  border: 1px solid #EBEFF5;
  border-right: 0px;
  border-bottom: 0px;
  text-align: left;
  font-weight: 400;
  padding: 0px 10px 10px 10px;
}

.eliminate-row>:last-child {
  border: 1px solid #EBEFF5;
  border-bottom: 0px;
}

.eliminate-form>:last-child {
  border: 1px solid #EBEFF5;
  border-top: 0px;
  border-right: 0px;
  border-left: 0px;
}

.eliminate-form>:last-child .el-col {
  padding: 0px;
}
</style>